#include <stdio.h>
#include <assert.h>

//void rotate(int* nums, int numsSize, int k) {
//    int tmp = 0;
//    for (int i = 0; i < k; ++i) {
//        tmp = nums[numsSize - 1];
//        for (int j = numsSize - 1; j > 0; --j) {
//            nums[j] = nums[j - 1];
//        }
//        nums[0] = tmp;
//    }
//}

void swap(int* num, int forn, int rear) {
    if (forn >= 0 && rear >= 0) {
        while (forn < rear) {
            int tmp = num[forn];
            num[forn] = num[rear];
            num[rear] = tmp;
            forn++;
            rear--;
        }
    }
}

void rotate(int* nums, int numsSize, int k) {
    if (k > numsSize) {
        k %= numsSize;
    }
    swap(nums, 0, numsSize - k - 1);
    swap(nums, numsSize - k, numsSize - 1);
    swap(nums, 0, numsSize - 1);
}

int main() {
    int arr[] = { 1, 2, 3 };
    int sz = sizeof(arr) / sizeof(arr[0]);
    rotate(arr, sz, 4);

    for (int i = 0; i < sz; i++) {
        printf("%d, ", arr[i]);
    }

    return 0;
}